package com.five.wisdomEat.service;

import com.five.wisdomEat.entity.Application;
import com.five.wisdomEat.entity.ResponseMessage;
import com.five.wisdomEat.mapper.ApplicationMapper;
import com.five.wisdomEat.mapper.BusinessMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ApplicationService {
    @Autowired
    private ApplicationMapper mapper;

    @Autowired
    private BusinessMapper businessMapper;

    public ResponseMessage selectApplicationList(){
        ResponseMessage message = new ResponseMessage();
        message.setMessage("查询成功");
        message.setSuccess(true);
        message.setData(mapper.selectApplicationList());
        message.setTotal(message.getData().size());
        return message;
    }

    public ResponseMessage insertApplication(Application application){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.insertApplication(application)>0;
        if(flag){
            message.setMessage("添加成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("添加失败");
            message.setSuccess(flag);
        }
        return message;
    }

    public ResponseMessage applyApplication(Application application,String bNumber){
        ResponseMessage message = new ResponseMessage();
        Boolean flag1 = mapper.applyApplication(application)>0;
        Boolean flag2 = businessMapper.businessJoin(bNumber)>0;
        if(flag1 && flag2){
            message.setMessage("同意成功");
            message.setSuccess(flag1);
        }else {
            message.setMessage("同意失败");
            message.setSuccess(flag1);
        }
        return message;
    }

    public ResponseMessage refuseApplication(Application application){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.refuseApplication(application)>0;
        if(flag){
            message.setMessage("拒绝成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("拒绝失败");
            message.setSuccess(flag);
        }
        return message;
    }

    public Integer selectApplicationCount(){
        return mapper.selectApplicationCount();
    }
}
